
data "vsphere_datacenter" "datacenter" {
      name = "Datacenter-TEST"
}

data "vsphere_datastore" "datastore" {
  name          = "Datastore"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_resource_pool" "pool" {
  name          = "vmware-test"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_network" "network" { 
  name          = "VM Network"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}

data "vsphere_virtual_machine" "template" {
  name          = "vds-test"
  datacenter_id = data.vsphere_datacenter.datacenter.id
}


resource "vsphere_virtual_machine" "vm" {
  name             = "lyh-test2"
  resource_pool_id = data.vsphere_resource_pool.pool.id
  datastore_id     = data.vsphere_datastore.datastore.id
  num_cpus         = 1
  memory           = 1024
  guest_id         = data.vsphere_virtual_machine.template.guest_id
  network_interface {
    network_id = data.vsphere_network.network.id
  }
  disk {
    label = "disk1"
    size  = 10
  }
  
    clone {
    template_uuid = data.vsphere_virtual_machine.template.id
    customize {
    linux_options {
        host_name = "lyh"
        domain    = "test.internal"
      }
      network_interface {
        ipv4_address = "10.0.0.22"
        ipv4_netmask = 16
      }
      ipv4_gateway = "10.0.0.1"
    }
  }
}

resource "ansible_host" "shell-exec" {
  count              = 1
  inventory_hostname = "10.0.0.22"
  groups             = ["shell-exec"]
  vars = {
  }
}
